package com.takepoints.mobile;

import com.takepoints.android.bo.Card;
import com.takepoints.android.services.TPServices;
import com.takepoints.mobile.zxing.CaptureActivity;
import com.takepoints.android.util.DownloadImageTask;
import com.takepoints.android.util.StringUtil;
import com.takepoints.android.util.UserInterfaceUtil;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

public class MyCardDetail extends BaseActivity {
	
	private int cardId;
	private String siteName;
	//private int totalOrng;
	private boolean isFromTakeNow = false;
	
	private Card card = null;
	//private ImgOrangeAdapter orangeAdapter = null;
	private int density = DisplayMetrics.DENSITY_DEFAULT;
	
	private final int STAMP_SIZE = 60;
	
	private final String IMG_PATH = "https://www.takepoints.com/public/uploads/mobile/";
	private final String IMG_REWARD_PATH = "https://www.takepoints.com/public/uploads/reward/thumb/";
	
	public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mycarddetail);
        manageMenu(3);
        
		density = getResources().getDisplayMetrics().densityDpi;
        
        Bundle bundle = this.getIntent().getExtras();
    	cardId = Integer.parseInt(bundle.getString("cardId"));
        siteName = bundle.getString("siteName");
    	//totalOrng  = (!StringUtil.isEmpty(bundle.getString("totalOrng"))?Integer.parseInt(bundle.getString("totalOrng")):-1);
        try{
        	isFromTakeNow = "Y".equals(bundle.getString("takeNow"));
        } catch(Exception e){ }
        
        LinearLayout lnrContent = (LinearLayout)findViewById(R.id.lnrContent);
        lnrContent.getBackground().setAlpha(200);
        
        TextView lblHeader = (TextView)findViewById(R.id.lblHeader);
        if(!StringUtil.isEmpty(siteName)){
        	lblHeader.setText(siteName);
        }
    	processCardDetail();
	}
	
	private void processCardDetail(){
		final ProgressDialog dialog = ProgressDialog.show(this, "Takepoints.com", "Loading Detail ...", true);
		final Handler handler = new Handler() {
        	public void handleMessage(Message msg) {
        		if(card != null){
	            	int star = card.getStar()!=null? Integer.parseInt(card.getStar()) : 0;
	            	int approved = card.getApprove()!=null? Integer.parseInt(card.getApprove()) : 0;
	            	
        			ImageView imgItem = (ImageView)findViewById(R.id.imgItem);
        			if(imgItem != null){
        				Bitmap bitmap = BitmapFactory.decodeFile(IMG_CACHE_PATH + card.getImageName());
        				if(bitmap != null){
        					if(star > 0 && approved >= star){
        						Drawable d = new BitmapDrawable(bitmap);
        						imgItem.setBackgroundDrawable(d);
        						imgItem.setImageResource(R.drawable.card_full);
        					} else{
        						imgItem.setImageBitmap(bitmap);
        					}
        				} else{
        					if(star > 0 && approved >= star){
        						imgItem.setImageResource(R.drawable.card_full);
        					}
        					imgItem.setTag(IMG_PATH + card.getImageName());
            				new DownloadImageTask().execute(imgItem);
        				}
        			}
        			
        			TextView txtCardName = (TextView)findViewById(R.id.txtCardName);
        			txtCardName.setText(card.getItemName());
        			txtCardName.setTextColor(Color.parseColor("#555555"));
        			//txtCardName.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        			
        			TextView txtCardExpire = (TextView)findViewById(R.id.txtCardExpire);
        			txtCardExpire.setText("ภายในวันที่ " + card.getEndDate());
        			
        			LinearLayout lnrContent = (LinearLayout)findViewById(R.id.lnrContent);
        			
        			/* ======================= Calculate Oranges ======================= */
    				int total = 0;
    				if(card.getStar() != null){
    					total = card.getStar()!=null? Integer.parseInt(card.getStar().trim()) : 0;
    				}
    				int appv = card.getApprove()!=null? Integer.parseInt(card.getApprove()) : 0;
    				int pend = card.getPending()!=null? Integer.parseInt(card.getPending()) : 0;
    				
    				int level1 = -1;
    				int level2 = -1;
    				int level3 = -1;
    				int added = 0;
    				if(!StringUtil.isEmpty(card.getLevel1())){
    					added++;
    					level1 = Integer.parseInt(card.getLevel1().trim());
    				}
    				if(!StringUtil.isEmpty(card.getLevel2())){
    					added++;
    					level2 = Integer.parseInt(card.getLevel2().trim()) + 1;
    				}
    				if(!StringUtil.isEmpty(card.getLevel3())){
    					added++;
    					level3 = Integer.parseInt(card.getLevel3().trim()) + 2;
    				}
    				
    		        Integer[] orangeIds = new Integer[total + added];
    		        Integer[] orangeNum = new Integer[total + added];
    		        for(int i=0, num=1; i<(total + added); i++){
    		        	if(i == level1){
    		        		orangeIds[i] = 1111;
    		        		orangeNum[i] = 0;
    		        	} else if(i == level2){
    		        		orangeIds[i] = 2222;
    		        		orangeNum[i] = 0;
    		        	} else if(i == level3){
    		        		orangeIds[i] = 3333;
    		        		orangeNum[i] = 0;
    		        	} else{
    		        		if(appv > 0){
    		        			orangeIds[i] = R.drawable.orangeapprove;
    		        			--appv;
    		        			--pend;
    		        		} else if(pend > 0){
    		        			orangeIds[i] = R.drawable.orangepending;
    		        			--pend;
    		        		} else{
    		        			orangeIds[i] = R.drawable.orangestart;
    		        		}
    		        		orangeNum[i] = num++;
    		        	}
    		        }
    		        /* ===================== End Calculate Oranges ===================== */
    		        
    		        GridView gridOrange = new GridView(lnrContent.getContext());
    		        gridOrange.setBackgroundResource(R.drawable.card_bg);
    		        if((total+added) > 14){
	    		        int remain = (total+added) - 14;
			        	int expand = remain>=7?((int)(remain / 7)):0;
			        	if((remain % 7) > 0){
			        		expand += 1;
			        	}
			        	//gridOrange.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 166+(84*expand)));
			        	int dp = UserInterfaceUtil.pixel2dp(density, (STAMP_SIZE + 9) * 2);
			        	int exp = UserInterfaceUtil.pixel2dp(density, (STAMP_SIZE + 9));
			        	gridOrange.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, dp+(exp*expand)));
			        	
		        	} else{
						//gridOrange.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 166));
		        		int dp = UserInterfaceUtil.pixel2dp(density, (STAMP_SIZE + 9) * 2);
		        		gridOrange.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, dp ));
		        	}
    		        gridOrange.setPadding(1, 1, 1, 1);
    		        gridOrange.setNumColumns(GridView.AUTO_FIT);
    		        //gridOrange.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    		        gridOrange.setHorizontalSpacing(3);
    		        gridOrange.setVerticalSpacing(3);
    		        gridOrange.setColumnWidth(UserInterfaceUtil.pixel2dp(density, STAMP_SIZE));
    		        
    		        ImgOrangeAdapter orangeAdapter = new ImgOrangeAdapter(gridOrange.getContext());
    		        orangeAdapter.setOrangesDisplay(orangeIds, orangeNum);
    		        gridOrange.setAdapter(orangeAdapter);
    		        
    		        lnrContent.addView(gridOrange);

    		        LinearLayout.LayoutParams rewardLayoutParam = new LinearLayout.LayoutParams(UserInterfaceUtil.pixel2dp(density, 222), LayoutParams.WRAP_CONTENT);
    		        rewardLayoutParam.setMargins(2, 5, 2, 1);
    		        
	        	    LinearLayout rewardRow = new LinearLayout(lnrContent.getContext());
	        	    rewardRow.setOrientation(LinearLayout.HORIZONTAL);
	        	    	LinearLayout.LayoutParams rowParam = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
	        	    	rowParam.setMargins(0, 4, 0, 4);
	        	    	rewardRow.setLayoutParams( rowParam );
	        	    
    		        if(!StringUtil.isEmpty(card.getLevel1())){		// Reward Level 1
		        	    rewardRow.addView( createRewardLayout(rewardRow.getContext(), card.getLevel1(), card.getImgLevel1(), "Y".equalsIgnoreCase(card.getRewardedLev1())) );
    		        }
    		        if(!StringUtil.isEmpty(card.getLevel2())){		// Reward Level 2
		        	    rewardRow.addView( createRewardLayout(rewardRow.getContext(), card.getLevel2(), card.getImgLevel2(), "Y".equalsIgnoreCase(card.getRewardedLev2())) );
    		        }
	        	    lnrContent.addView(rewardRow);		// Add Reward #1 , #2
	        	    
    		        if(!StringUtil.isEmpty(card.getLevel3())){		// Reward Level 3
		        	    lnrContent.addView( createRewardLayout(rewardRow.getContext(), card.getLevel3(), card.getImgLevel3(), "Y".equalsIgnoreCase(card.getRewardedLev3())) );
    		        }
	        	    
    				/* ========================= Card Detail  ========================= */
				    TableRow trDetail = new TableRow(lnrContent.getContext());
				    trDetail.setBackgroundResource(R.drawable.info_middle);
        	    	TableRow.LayoutParams trDetailParam = new TableRow.LayoutParams( TableRow.LayoutParams.FILL_PARENT
        	    															  , TableRow.LayoutParams.WRAP_CONTENT);
        	    	trDetailParam.setMargins(1, 5, 1, 3);
        	    	trDetail.setLayoutParams(trDetailParam);
	        	        TextView txtOfferLine1 = new TextView(trDetail.getContext());
	        	        txtOfferLine1.setText(StringUtil.nvl(card.getOfferLine1(), StringUtil.BLANK));
	        	        txtOfferLine1.setTextSize(11);
	        	        txtOfferLine1.setTextColor(Color.GRAY);
	        	        txtOfferLine1.setHeight(LayoutParams.WRAP_CONTENT);
	        	        txtOfferLine1.setPadding(5, 3, 5, 3);
	        	        txtOfferLine1.setSingleLine(false);
	        	        txtOfferLine1.setGravity(Gravity.TOP);
	        	        trDetail.addView(txtOfferLine1);
	        	    lnrContent.addView(trDetail);
        		}
        		dialog.dismiss();
        		if(isFromTakeNow){
        			popup("ได้แสตมป์ส้มเพิ่มแล้ว ..");
        		} else{
        			popup("กด Take .. เพื่อรับแสตมป์ส้ม");
        		}
        	}
		};
        Thread thread = new Thread(){  
        	public void run(){
        		card = TPServices.getMyItemDetail(cardId);
        		handler.sendEmptyMessage(0);
        	}
        };
        thread.start();
	}
	
	private RelativeLayout createRewardLayout(Context ctx, final String orangeLevel, String imgLevel, boolean isRewarded){
		RelativeLayout rewardsLine = new RelativeLayout(ctx);
        rewardsLine.setBackgroundResource(R.drawable.button_info);
        rewardsLine.setPadding(4, 3, 4, 4);
	        RelativeLayout.LayoutParams prm = new RelativeLayout.LayoutParams(UserInterfaceUtil.pixel2dp(density, 222), LayoutParams.WRAP_CONTENT);
	        prm.setMargins(3, 2, 3, 3);
	        rewardsLine.setLayoutParams(prm);
        
        ImageView img = new ImageView(rewardsLine.getContext());
        img.setBackgroundResource(R.drawable.grid_reward);
        img.setPadding(2, 2, 2, 2);
        img.setScaleType(ScaleType.FIT_XY);
	    Bitmap bm = BitmapFactory.decodeFile(IMG_CACHE_PATH + imgLevel);
	    if(bm != null){
	    	img.setImageBitmap(bm);
		} else{
			img.setTag(IMG_REWARD_PATH + imgLevel);
			new DownloadImageTask().execute(img);
		}
	    int imgRewardSize = UserInterfaceUtil.pixel2dp(density, STAMP_SIZE+20);
	    	RelativeLayout.LayoutParams imgParam = new RelativeLayout.LayoutParams(imgRewardSize, imgRewardSize);
	    	imgParam.setMargins(2, 2, 6, 3);
	    	imgParam.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		    rewardsLine.addView(img, imgParam);
	    
	    TextView txtLevel = new TextView(rewardsLine.getContext());
	    txtLevel.setText("ใช้ส้ม " + orangeLevel + " ผล");
	    txtLevel.setTextSize(11);
	    txtLevel.setTextColor(Color.GRAY);
    	    RelativeLayout.LayoutParams txtParam = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    	    txtParam.setMargins(2, 2, 6, 2);
    	    txtParam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    	    txtParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	    rewardsLine.addView(txtLevel, txtParam);
	    
	    TextView btnLevel = new TextView(rewardsLine.getContext());
	    btnLevel.setTextSize(16);
	    btnLevel.setTextColor(Color.WHITE);
	    btnLevel.setGravity(Gravity.CENTER);
	    btnLevel.setPadding(9, 12, 9, 12);
    	    RelativeLayout.LayoutParams btnparam = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    	    btnparam.setMargins((imgRewardSize+6), 2, 2, 2);
    	    btnparam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    	    btnparam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    	
	    if(isRewarded){
		    btnLevel.setText("แลกแล้ว");
		    btnLevel.setBackgroundResource(R.drawable.button_used);
		    rewardsLine.addView(btnLevel, btnparam);
	    	
	    } else{
		    if(Integer.parseInt(card.getApprove()) >= Integer.parseInt(orangeLevel)){
			    btnLevel.setText("แลก");
			    btnLevel.setBackgroundResource(R.drawable.button_use);
			    rewardsLine.addView(btnLevel, btnparam);
			    
			    rewardsLine.setOnClickListener(new View.OnClickListener(){
		            public void onClick(View view){
		            	processReward(orangeLevel);
		            }
		        });
		    }
	    }
	    
	    return rewardsLine;
	}
	
	public class ImgOrangeAdapter extends BaseAdapter {
		
    	private Context mContext;
    	private Integer[] mThumbIds = {};
    	private Integer[] orangeNums = {};
    	
    	public ImgOrangeAdapter(Context c){
			mContext = c;
		}
    	
    	public void setOrangesDisplay(Integer[] mThumbIds, Integer[] orangeNums){
    		this.mThumbIds = mThumbIds;
    		this.orangeNums = orangeNums;
    	}
    	
    	public View getView(final int position, View convertView, ViewGroup parent){
    		ImageView imageView = null;
			 
			 if(mThumbIds[position] == 1111){
				 /*
				 if("Y".equalsIgnoreCase(card.getRewardedLev1())){
					 imageView = new ImageView(mContext){
						 @Override
						 public void onDraw(Canvas canvas) {
							 / * Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
							 p.setColor(Color.parseColor("#FF8E01"));
							 p.setStrokeWidth(2);
							 canvas.drawLine(0, 0, 75, 75, p);
							 canvas.drawLine(75, 0, 0, 75, p); * /
							 Paint p = new Paint();
							 //p.setARGB(255, 255, 255, 255);
							 p.setColor(Color.parseColor("#333333"));
							 //p.setTextAlign(Paint.Align.CENTER);
						     p.setTextSize(22);
						     canvas.drawText("แลก", 20, 20, p);
						     canvas.drawText("แล้ว", 20, 45, p);
						     canvas.rotate((int)(32 * 180 / Math.PI), getWidth() >> 1, getHeight() >> 1);
						     super.onDraw(canvas);
						 }
					 };
					 imageView.setBackgroundColor(Color.TRANSPARENT);
					 imageView.setAlpha(150);
					 
				 } else{
					 if(Integer.parseInt(card.getApprove()) >= Integer.parseInt(card.getLevel1())){
						 imageView = new ImageViewRounded(mContext);
						 imageView.setBackgroundColor(Color.TRANSPARENT);
						 imageView.setOnClickListener(new View.OnClickListener(){
				            public void onClick(View view){
				            	Intent myCardRewardInt = new Intent(view.getContext(), MyCardRewardDetail.class);
				            	myCardRewardInt.putExtra("cardId", card.getItemId());
				            	myCardRewardInt.putExtra("promotionId", card.getPromotionId());
				            	myCardRewardInt.putExtra("rewardNum", card.getLevel1());
				            	startActivityForResult(myCardRewardInt, 0);
				            }
				        });
					 } else{
						 imageView = new ImageView(mContext);
						 imageView.setAlpha(100);
					 }
				 }
				 */
				 imageView = new ImageView(mContext);
				 imageView.setBackgroundColor(Color.TRANSPARENT);
				 int rewardGridDP = UserInterfaceUtil.pixel2dp(density, STAMP_SIZE);
				 imageView.setLayoutParams( new GridView.LayoutParams(rewardGridDP, rewardGridDP) );
				 imageView.setBackgroundResource(R.drawable.grid_reward);
				 imageView.setScaleType(ScaleType.FIT_XY);
				 imageView.setPadding(2, 2, 2, 2);
				 
				 Bitmap bitmap = BitmapFactory.decodeFile(IMG_CACHE_PATH + card.getImgLevel1());
				 if(bitmap != null){
					 imageView.setImageBitmap(bitmap);
				 } else{
					 imageView.setTag(IMG_REWARD_PATH + card.getImgLevel1());
					 new DownloadImageTask().execute(imageView);
				 }
				 
			 } else if(mThumbIds[position] == 2222){
				 
				 imageView = new ImageView(mContext);
				 imageView.setBackgroundColor(Color.TRANSPARENT);
				 int rewardGridDP = UserInterfaceUtil.pixel2dp(density, STAMP_SIZE);
				 imageView.setLayoutParams( new GridView.LayoutParams(rewardGridDP, rewardGridDP) );
				 imageView.setBackgroundResource(R.drawable.grid_reward);
				 imageView.setScaleType(ScaleType.FIT_XY);
				 imageView.setPadding(2, 2, 2, 2);
				 
				 Bitmap bitmap = BitmapFactory.decodeFile(IMG_CACHE_PATH + card.getImgLevel2());
				 if(bitmap != null){
					 imageView.setImageBitmap(bitmap);
				 } else{
					 imageView.setTag(IMG_REWARD_PATH + card.getImgLevel2());
					 new DownloadImageTask().execute(imageView);
				 }
				 
			 } else if(mThumbIds[position] == 3333){
				 
				 imageView = new ImageView(mContext);
				 imageView.setBackgroundColor(Color.TRANSPARENT);
				 int rewardGridDP = UserInterfaceUtil.pixel2dp(density, STAMP_SIZE);
				 imageView.setLayoutParams( new GridView.LayoutParams(rewardGridDP, rewardGridDP) );
				 imageView.setBackgroundResource(R.drawable.grid_reward);
				 imageView.setScaleType(ScaleType.FIT_XY);
				 imageView.setPadding(2, 2, 2, 2);
				 
				 Bitmap bitmap = BitmapFactory.decodeFile(IMG_CACHE_PATH + card.getImgLevel3());
				 if(bitmap != null){
					 imageView.setImageBitmap(bitmap);
				 } else{
					 imageView.setTag(IMG_REWARD_PATH + card.getImgLevel3());
					 new DownloadImageTask().execute(imageView);
				 }
				 
			 } else{
				 //int gridDP = UserInterfaceUtil.pixel2dp(density, 65);
				 int gridDP = UserInterfaceUtil.pixel2dp(density, (STAMP_SIZE));
				 
				 final String num = String.valueOf( orangeNums[position] );
				 imageView = new ImageView(mContext){
					 @Override
					 public void onDraw(Canvas canvas) {
						 Paint p = new Paint();
						 p.setColor(Color.parseColor("#444444"));
						 p.setStyle(Paint.Style.STROKE);
						 p.setStrokeWidth(2);
					     p.setTextSize(19);
						 float numLen = p.measureText(num);
						 float x = (getWidth() - numLen)/2; 
						 float y =  -p.ascent() + (getHeight() * 0.46f);
					     canvas.drawText(num, x, y, p);
					     super.onDraw(canvas);
					 }
				 };
				 imageView.setLayoutParams(new GridView.LayoutParams(gridDP, gridDP));
				 imageView.setBackgroundResource(R.drawable.grid_orange);
				 imageView.setImageResource(mThumbIds[position]);
				 imageView.setScaleType(ScaleType.CENTER_INSIDE);
			 }
			 imageView.setPadding(2, 2, 2, 2);
			 return imageView;
    	}
    	
    	@Override
		public int getCount(){
			return mThumbIds.length;
		}
    	@Override
		public Object getItem(int arg0){
			return null;
		}
		@Override
		public long getItemId(int position){
			return position;
		}
	}
	/*
	@Override
	public void onBackPressed(){
		Intent myCardsInt = new Intent(this, MyCards.class);
		startActivityForResult(myCardsInt, 0);
		return;
	}
	*/
	protected void processTake(Context ctx){
		PackageManager pckMng = getPackageManager();
		if (pckMng != null && pckMng.hasSystemFeature(PackageManager.FEATURE_NFC)) {
			checkNfcStatus(null);
		} else{
			gotoVerifyCode();
		}
	}
	private void processReward(String levelRewardNum){
		PackageManager pckMng = getPackageManager();
		if (pckMng != null && pckMng.hasSystemFeature(PackageManager.FEATURE_NFC)) {
			checkNfcStatus(levelRewardNum);
		} else{
			gotoVerifyCode(levelRewardNum);
		}
	}
	
	@TargetApi(10)
	private void checkNfcStatus(String levelRewardNum){
		NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter();
    	if(nfcAdapter.isEnabled()){
    		if(levelRewardNum == null){
        		gotoVerifyCodeNFC();
    		} else{
    			gotoVerifyCodeNFC(levelRewardNum);
    		}
    	} else{
    		confirmNfcSetting(levelRewardNum);
    	}
	}
	
	private void confirmNfcSetting(final String levelRewardNum){
		final AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
		alertbox.setMessage("NFC ถูกปิดอยู่ !\n\nคุณต้องการเปิด NFC ใช่หรือไม่ ?");
		alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dlgInf, int which) {
				gotoNetworkSetting();
			}
		});
		alertbox.setNeutralButton("No", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dlgInf, int which) {
				if(levelRewardNum == null)
					gotoVerifyCode();
				else
					gotoVerifyCode(levelRewardNum);
			}
		});
		alertbox.show();
	}
    private final void gotoNetworkSetting(){
    	startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
    }
    
    private final void gotoVerifyCode(){
    	Intent verifyInt = new Intent(this, CaptureActivity.class);
    	verifyInt.putExtra("cardId", card.getItemId());
    	verifyInt.putExtra("siteName", siteName);
    	verifyInt.putExtra("pageSrc", "MyCardDetail");
    	startActivityForResult(verifyInt, 0);
    }
	
	private void gotoVerifyCodeNFC(){
    	Intent verifyInt = new Intent(this, VerifyCodeNFC.class);
    	verifyInt.putExtra("cardId", card.getItemId());
    	verifyInt.putExtra("siteName", siteName);
    	verifyInt.putExtra("pageSrc", "MyCardDetail");
    	startActivityForResult(verifyInt, 0);
    }
	
	private final void gotoVerifyCode(String levelRewardNum){
    	Intent verifyInt = new Intent(this, CaptureActivity.class);
		verifyInt.putExtra("pageSrc", "MyCardRewardDetail");
    	verifyInt.putExtra("cardId", card.getItemId());
		verifyInt.putExtra("promotionId", card.getPromotionId());
		verifyInt.putExtra("rewardNum", levelRewardNum);
    	startActivityForResult(verifyInt, 0);
    }
	
	private void gotoVerifyCodeNFC(String levelRewardNum){
    	Intent verifyInt = new Intent(this, VerifyCodeNFC.class);
    	verifyInt.putExtra("pageSrc", "MyCardRewardDetail");
    	verifyInt.putExtra("cardId", card.getItemId());
		verifyInt.putExtra("promotionId", card.getPromotionId());
    	verifyInt.putExtra("rewardNum", levelRewardNum);
    	startActivityForResult(verifyInt, 0);
    }
	
	/*private final class WallPostListener extends BaseRequestListener {
		@Override
		public void onComplete(String response, Object state) {
			mRunOnUi.post(new Runnable() {
				@Override
				public void run() {
					mProgress.cancel();
					Toast.makeText(MyCardDetail.this, "Posted to Facebook", Toast.LENGTH_SHORT).show();
				}
			});
		}
	}*/
	
}
